// 本地存储的封装

export function setStorageToken(payload) {
  localStorage.setItem('token', JSON.stringify(payload))
}

export function getStorageToken() {
  return JSON.parse(localStorage.getItem('token')) || {}
}

export function removeStorageToken() {
  localStorage.removeItem('token')
}
const CHANNEL_NAME = 'hm-news-channel-list'

// 存储channel 频道操作
export function setStroageChannel(payload) {
  localStorage.setItem(CHANNEL_NAME, JSON.stringify(payload))
}

export function getStroageChannel() {
  // 获取channel的结果，还需要将其返回出去
  // 不需要去设置默认值 空对象，因为一旦本地中获取不到频道的数据，就会去发送请求来获取频道的数据
  return JSON.parse(localStorage.getItem(CHANNEL_NAME))
}

const SEARCH_HISTORY_NAME = 'hm-news-search-list'

// 存搜索的历史记录
export function setStroageSearchHistory(payload) {
  localStorage.setItem(SEARCH_HISTORY_NAME, JSON.stringify(payload))
}

export function getStroageSearchHistory() {
  return JSON.parse(localStorage.getItem(SEARCH_HISTORY_NAME)) || []
}
